package com.gupao.micro.services.mvc.controller;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.gupao.micro.services.mvc.annotation.OptionsMapping;

/**  
 * @Title: CacheRestController.java
 * @Description: TODO(用一句话描述该文件做什么)
 * @date 2018年8月15日 上午2:22:26
 * @version V1.0  
 */
@Controller
public class CacheRestController {
	
	@RequestMapping
	@ResponseBody //没有缓存 -》304服务器和客户端没有形成默契（状态码）
	public String helloWorld(){
		return "Hello, World"; //Body = "Hello, World"
	}
	
	@RequestMapping("/cache")
	@OptionsMapping(name="")
	public ResponseEntity<String> cacheHelloWorld(
			@RequestParam(required=false, defaultValue="false") boolean cached){
		if(cached){
			ResponseEntity<String> entity = new ResponseEntity("Hello, World", HttpStatus.NOT_MODIFIED);
			return entity;
		} else {
			return ResponseEntity.ok("Hello, World");
		}
		
	}
}
